home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / tc_tsr10.zip / TSR_LIST.TXT < prev    next >
Text File  |  1991-06-18  |  7KB  |  167 lines

  1. TSR_LIST.TXT
  2.  
  3. Here is some documentation I wrote some time ago. Hope it's useful, but,
  4.  
  5.      The author shall not be liable to the user for any direct, indirect or
  6.      consequential loss arising from the use of, or inability to use, any
  7.      program or file howsoever caused. No warranty is given that the programs
  8.      will work under all circumstances.
  9.  
  10. Sherif
  11.  
  12. /*--------------------------------------------------------------------------*
  13.  | Sherif El-Kassas        .       :.                                       |
  14.  | EB dept           \_____o__/ __________                                  |
  15.  | Eindhoven U of Tec       .. /                                            |
  16.  | The Netherlands            /             Email: elkassas@eb.ele.tue.nl   |
  17.  *--------------------------------------------------------------------------*/
  18.  
  19.  
  20. TSR LIST
  21.  
  22. Sherif El-Kassas
  23. February 1989
  24.  
  25.  
  26. Memory resident utilities are among the most popular applications used on
  27. MS-DOS based machines.
  28. However, not all implementations of TSR (Terminate but Stay Resident) programs
  29. are completely safe to use. Loading some TSRs in the wrong sequence can result
  30. in a system crash, which means you will have to reboot, thus loosing any data
  31. stored in RAM. Even with the most robust TSRs, attempting to uninstall memory
  32. resident applications in the wrong sequence will leave your system in a
  33. unpredictable (messy) state.
  34.  
  35. [
  36. For example try the following:
  37.  
  38.  C> LIGHT      (load Turbo Lightening)
  39.  C> SK         (load SideKick)
  40.  C> LIGHT /K   (uninstall Turbo Lightening)
  41.  
  42. Now try activating SideKick (by pressing it's hot-key), or even reloading a
  43. new copy of SideKick into RAM.  You will find that SideKick detects that it's
  44. already loaded, and therefor refuses to reload, on the other hand it dos not
  45. respond to the hot-key !.  Obviously any unsaved data in SideKick's notepad is
  46. lost.
  47. ]
  48.  
  49. So it's helpful to know which TSRs are currently loaded, the sequence of
  50. loading, and which interrupt vectors are used by them, before
  51. loading/unloading a TSR.
  52.  
  53. TSR_LIST is a utility - written in Turbo C - that prints a list of programs
  54. that are currently loaded in your PC's memory.  It also prints a list of the
  55. interrupt vectors used (disabled) by each program.
  56.  
  57.  
  58. PREPARING TSR_LIST
  59.  
  60. After you type the C source code (i.e. TSR_LIST.C) compile it using the
  61. following commands:
  62.  
  63.     C> TCC TSR_LIST
  64.  
  65. Then to run the program simply type TSR_LIST and press enter.
  66.  
  67.  
  68. HOW TSR_LIST WORKS
  69.  
  70. TSR_LIST performs three main tasks:
  71.  
  72. o Finding the resident program;
  73. o Locating and printing it's name (it's not always possible); and
  74. o Printing the used interrupt vectors.
  75.  
  76.  
  77. FINDING THE RESIDENT PROGRAM
  78.  
  79. MS-DOS divides memory into a group of blocks, each block is preceded with a 16
  80. byte header called a memory control block (also called an arena header). A MCB
  81. (Memory Control Block) contains three important fields:
  82.  
  83. o A byte indicating whether this MCB is/isn't the last MCB in the chain
  84.   ('M' -> part of the chain, 'Z' -> end of the chain);
  85. o A word indicating the owner of the block (the owner's PSP address); and
  86. o A word indicating the size of the block in paragraphs.
  87.  
  88. When MS-DOS loads a program into memory, it allocates two memory blocks for
  89. it. The first is for the program's environment space, and the second is for
  90. the program itself. The owner fields in the two MCBs point to the program's
  91. PSP (i.e. a program's MCB owns its self). Therefore finding a resident program
  92. means scanning all valid MCBs until we find a MCB that owns its self.
  93.  
  94.  
  95. LOCATING AND PRINTING THE PROGRAM'S NAME
  96.  
  97. The program's environment block contain a series of ASCIIZ strings (an ASCIIZ
  98. string is a null terminated character string). The end of the set of strings
  99. is indicated by an additional null character. Under MS-DOS versions 3.0 and
  100. higher, two additional fields are added to the environment block. The first is
  101. a word count field, and the second is the full path and name of the program.
  102. The address of the environment block is kept at offset 0x2C of the program's
  103. PSP.
  104.  
  105.  
  106. PRINTING THE USED INTERRUPT VECTORS
  107.  
  108. The first 1K bytes of RAM are called the interrupt vector table. Each entry in
  109. the table is 4 bytes long, and contains the segment and offset of the
  110. interrupt service routine (00 to 0xFF).  So finding the used interrupts means
  111. scanning the interrupt table for an address that lies in the range occupied by
  112. the resident program.
  113.  
  114.  
  115. So TSR_LIST scans the chain of MCBs, whenever it finds a program (a block that
  116. owns its self) it first gets the program's name from it's environment space,
  117. and then scans the interrupt vector table (at 0:0) to find the used
  118. interrupts.
  119.  
  120.  
  121.  
  122. PSP                                   Environment Segment
  123. 00 +-----------------------+         +-------------------+
  124. :  |                       |    +--->|VAR1=STRING <null> |
  125. 2C +-----------------------|    |    |VAR2=STRING <null> |
  126.    |Environment Segment    +----+    |:                  |
  127. 2E +-----------------------|         |:                  |
  128. :  |                       |         |VARn=STRING <null> |
  129. :  +-----------------------|         |<null> <num words> |
  130. :  |                       |         |PROGRAM NAME <null>|
  131. FF +-----------------------+         |                   |
  132.                                      +-------------------+
  133.  
  134.             FIG.1 RELEVANT PARTS PSP AND ENVIRONMENT SPACE STRUCTURE
  135.  
  136.  
  137. PSP (program name is c:\utils\sk\sk.com)
  138.  
  139.    cs:0000 CD 20 00 A0 00 9A F0 FE 1D F0 60 03 83 59 2D 03 M    .p~ p` Y-
  140.    cs:0010 83 59 2F 02 B2 5E C5 44 01 01 01 0 +--+--+ F FF .Y/ 2^+D     ...
  141.    cs:0020 FF FF FF FF FF FF FF FF FF FF FF F |86|83| 0 B1 ................
  142.    :                                          +--+--+
  143.    :                                             |
  144.    cs:00F0 0A 90 F0 B3 00 00 14 B3 18 00 DA 5B 0A|90 20 B3 .p|  .|  +[. |
  145.                                                  |
  146. Dump of Environment Space                        |
  147.    +---------------------------------------------+
  148. +--+-+
  149. |8386:0000 43 4F 4D 53 50 45 43 3D 43 3A 5C 43 4F 4D 4D 41  COMSPEC=C:\COMMA
  150. +----+0010 4E 44 2E 43 4F 4D 00 50 41 54 48 3D 43 3A 5C 44  ND.COM PATH=C:\D
  151.  8386:0020 4F 53 00 50 52 4F 4D 50 54 3D 24 50 24 4 |00|00| OS PROMPT=$P$G
  152.  8386:0030|01|00|43 3A 5C 55 54 49 4C 53 5C 53 4B 5 +--+--+|  C:\UTILS\SK\SK |
  153.  8386:004 +--+--+ F 4D 00                              |   |.COM             |
  154.              |                             +-----------+   +-------+---------+
  155.              |                             |                       |
  156.      Number of words field      Two zero bytes indicating      Program name
  157.                                 end of environment variables
  158.  
  159.  
  160.                 FIG.2 ACTUAL DUMP OF PSP AND ENVIRONMENT SPACE
  161.  
  162.  
  163. REFERENCES
  164. 1. Ray Duncan, "Advanced MS-DOS", MicroSoft press 1986.
  165. 2. Robert L. Hummel, "A Memory Mapping Utility", PC Magazine, August 1987.
  166. 3. Jeff Prosise, "Instant Access To Directories", PC Magazine, April 1987.
  167.